package com.shuaishuai.ketaiheadlines.action;

import com.alibaba.fastjson.JSON;
import com.shuaishuai.ketaiheadlines.biz.Userbiz;
import com.shuaishuai.ketaiheadlines.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/member")
public class Useraction {

    @Autowired(required = false)
    private Userbiz userbiz;
//    @CrossOrigin(origins = "http://localhost:8081", maxAge = 3600) // 允许
    @RequestMapping("/login")
    public Map<String,String> login(@RequestBody Users users){
        Map<String,String> map = new HashMap<>();
        Users user = userbiz.login(users);
        if(user!=null){
            map.put("user", JSON.toJSONString(user));
            map.put("status","200");
            map.put("msg","登录成功");
        }else {
            map.put("status","400");
            map.put("msg","登录失败");
        }
        return map;
    }
}
